package net.mmonbiter.ebs.treeinterp;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import net.moonbiter.OperationFailureException;
import net.moonbiter.ebs.protocols.httpparams.tree.Tree;
import net.moonbiter.ebs.protocols.httpparams.tree.building.ParamsTreeBuilder;
import net.moonbiter.ebs.protocols.httpparams.tree.interp.TreeInterpreter;
import net.moonbiter.ebs.protocols.httpparams.tree.interp.TreeInterpreterImpl;
import net.moonbiter.ebs.validation.ValidationException;

import org.junit.Test;

public class TreeInterpreting {
	
	@Test
	public void interpString(){
		TreeInterpreter treeInterp = new TreeInterpreterImpl();
		
		Tree t = new Tree();
		ParamsTreeBuilder b = new ParamsTreeBuilder();
		
		Map<String,String[]> params = new HashMap<String,String[]>();
		params.put("elements", new String[]{"1","2","3"});
		try {
			t = b.buildParamsTree(params);
		} catch (ValidationException e) {
			fail();
		}
		try {
			Integer[] integers = treeInterp.interpret(t, "elements", Integer[].class);
			assertSame(3,integers.length);
			assertSame(1,integers[0]);
			assertSame(2,integers[1]);
			assertSame(3,integers[2]);
			int[] ints = treeInterp.interpret(t, "elements", int[].class);
			assertSame(3,ints.length);
			assertSame(1,ints[0]);
			assertSame(2,ints[1]);
			assertSame(3,ints[2]);
		} catch (ValidationException e) {
			fail();
		} catch (OperationFailureException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
